Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luhn: tweak canonical tests #547

Merged
merged 2 commits into from
Feb 21, 2017
Merged

luhn: tweak canonical tests #547

merged 2 commits into from
Feb 21, 2017

Conversation

stkent
Copy link
Contributor

@stkent stkent commented Feb 12, 2017

No description provided.

@@ -11,7 +11,7 @@
"expected": false
},
{
"description": "simple valid sin",
"description": "simple valid SIN",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalized sin -> SIN throughout.

"description": "another valid Canadian SIN",
"input": "055 444 285",
"expected": true
},
Copy link
Contributor Author

@stkent stkent Feb 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR that added this test, the following reasoning was given:

Part of it was the contrast with 055-444-285, and part of it was the thought that having a couple of different longer valid numbers might help someone who was struggling to work out how the algorithm needed to be implemented.

I moved it earlier in the suite so that it is more likely encountered by someone who is still trying to work out the algorithm, and updated the language in the test cases that contrast with this one to make that comparison more clear.

"input": "046a 454 286",
"expected": false
},
{
"description": "punctuation is not allowed",
"description": "valid strings with punctuation included become invalid",
"input": "055-444-285",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare to valid case 055 444 285.

"input": "055-444-285",
"expected": false
},
{
"description": "symbols are not allowed",
"description": "valid strings with symbols included become invalid",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare to valid case 055 444 285.

{
"description": "another valid sin",
"input": "055 444 285",
"description": "more than a single zero is valid",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to state the limitation here more clearly, and moved the space character to indicate that a "chain" of zeros is not required.

"expected": true
},
{
"description": "nine doubled is nine",
"description": "input digit 9 is correctly converted to output digit 9",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nine doubled is not nine; tried to make this a little more explicit!

"description": "another valid sin",
"input": "055 444 285",
"description": "more than a single zero is valid",
"input": "00 000",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "0 0000" would be even better here?

@stkent
Copy link
Contributor Author

stkent commented Feb 12, 2017

I was also tempted to update the description for this test to make it more clear that this is the only test that will fail if the "wrong" set of alternating digits are manipulated. Thoughts on that?

    {
      "description": "simple valid sin",
      "input": " 5 9 ",
      "expected": true
    }

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good ordering change, good description change. Note that in #522 I was in doubt about whether 055 444 285 should be present at all (it is unlikely any student will come up with an implementation that passes all tests except that one).

I was also tempted to update the description for this test to make it more clear that this is the only test that will fail if the "wrong" set of alternating digits are manipulated

Indeed, I was very inspired by exercism/go#500

If you wanted to go one further to emphasize it, you could try this.

First, we have the case 059. This is a short valid SIN, but since it has an odd number of digits, it doesn't matter whether you double from the left or right.

Then, we have 59 which has an even number of digits to show that it's important to double the right digits.

@stkent
Copy link
Contributor Author

stkent commented Feb 12, 2017

Good call; I'll update that now!

@stkent
Copy link
Contributor Author

stkent commented Feb 12, 2017

@petertseng updated with a few changes:

  • removed doubled "valid Canadian SIN" test cases and simplified invalid cases to all be variants of the remaining valid SIN;
  • added early test using "059" and following valid test using "59";
  • updated the multiple-zeros test case to reduce possibility for misinterpretation.

@stkent
Copy link
Contributor Author

stkent commented Feb 12, 2017

@petertseng see also #549 which I believe addresses another potential source of confusion for implementors.

@michaelorr
Copy link

These changes look good to me. The descriptions and the test cases make sense and there doesn't seem to be enough overlap between them where they could be condensed down without sacrificing something. I don't have merge rights here but 👍 :shipit:

@ErikSchierboom ErikSchierboom merged commit 715e23e into master Feb 21, 2017
@ErikSchierboom ErikSchierboom deleted the luhn-tests branch February 21, 2017 08:02
@ErikSchierboom
Copy link
Member

Great work, thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants